#include "Camera.h"
#include <iostream>
using namespace std;

Camera::Camera() {
};

void Camera::setPoV1(CVector3 eye_, double el, double az, double rad) {
    eye=eye_;
    elevation=el;
    azimuth=az;
    radius=rad;
    PoV=1;}

void Camera::changeAng(float el, float az) { 
    elevation+=el;
    azimuth+=az;
    //if(elevation>pi/3)
    //   elevation-=el;
    //if(elevation<0.01)
    //   elevation-=el;
    return;
};

void Camera::useCam(void){
        
    if(elevation>-pi && elevation<0) 
       rc=-1;
    else
       rc=1;
    
    //firstpersonpoint of view
    if(PoV==0)
    {
    }
    
    if(PoV==1)
    {
       CVector3 pos=eye;
       pos.x+=radius*sin(elevation)*sin(azimuth);
       pos.y+=radius*cos(elevation);
       pos.z+=radius*sin(elevation)*cos(azimuth);
       position=pos;
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-1.6, 1.6, -1.0, 1.0, 2.0, 5000);
    glMatrixMode(GL_MODELVIEW);
    gluLookAt(position.x, position.y, position.z,
              eye.x, eye.y, eye.z,
              0.0,1.0*rc,0.0);
}

